package PaperExperiment;

import java.util.ArrayList;

public class CellGroup {
	ArrayList<Cell> listCell = null;
	
	public CellGroup() {
		this.listCell = new ArrayList<Cell>();
	}
	
	public void ACT001_addCell(Cell c) {
		this.listCell.add(c);
	}
	
	public boolean ACT002_checkAndAddNewCell(Cell c) {
		boolean isAdd = false;
		int index = 0;
		while(!isAdd && index < this.listCell.size()) {
			if(this.ACT004_isCloseCell(this.listCell.get(index), c)) {
				this.listCell.add(c);
				isAdd = true;
			}
			index = index + 1;
		}
		return isAdd;
	}
	
	public boolean ACT003_isBelongGroup(Cell c) {
		boolean isFound = false;
		int index = 0;
		while(!isFound && index < this.listCell.size()) {
			if(this.listCell.get(index).row == c.row && this.listCell.get(index).col == c.col) {
				isFound = true;
			}
			index = index + 1;
		}
		return isFound;
	}
	
	public boolean ACT004_isCloseCell(Cell c1, Cell c2) {
		return (Math.abs(c1.row - c2.row) <= 1) && (Math.abs(c1.col - c2.col) <= 1);
	}
}
